package com.example.day_01_02;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {
    private TextView textViewCounter;
    private Button buttonIncrease, buttonDecrease;
    private int count = 0;  // 用于存储点击次数

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 获取界面控件
        textViewCounter = findViewById(R.id.textViewCounter);
        buttonIncrease = findViewById(R.id.buttonIncrease);
        buttonDecrease = findViewById(R.id.buttonDecrease);

        // 设置按钮点击事件监听器

        // 增加按钮
        buttonIncrease.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                count++;  // 每次点击，计数器加一
                textViewCounter.setText(String.valueOf(count));  // 更新显示的计数
            }
        });

        // 减少按钮
        buttonDecrease.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                count--;  // 每次点击，计数器减一
                textViewCounter.setText(String.valueOf(count));  // 更新显示的计数
            }
        });
    }
}